<?php


/**
 * NOTICE OF LICENSE
 *
 * THIS SOURCE FILE IS PART OF EVEBIT'S PRIVATE PROJECT.
 * 
 * DO NOT USE THIS FILE IN OTHER PLACE.
 *
 * @package   App_Backend
 * @author    Cheng Wei <berlios.o@gmail.com>
 * @version   $$Id: Locale.php 20 2010-12-18 09:35:07Z cheng.wei $$
 * @copyright Copyright (c) 2008 Evebit Inc. China (http://www.evebit.com)
 */

/**
 * Options for locale / language
 * 
 * @package   App_Backend
 * @author    Cheng Wei <berlios.o@gmail.com>
 * @version   $$Id: Locale.php 20 2010-12-18 09:35:07Z cheng.wei $$
 */
class Default_Model_Config_Source_Locale extends Default_Model_Config_Source_Abstract {
	
	/**
	 * Get options of locale
	 * @return array
	 */
	public function getOptionsArray($all = false) {
		$locale = Evebit_Application::getSession()->getLocale();
		
		if ($all) {
			$options = array();
			
			foreach (Zend_Locale::getTranslationList('language', $locale) as $key => $lang) {
				if (strlen($key) == 2) {
					$options[$key] = ucfirst($lang);
				}
			}
			asort($options);
			
			return $options;
		}
		
		return array(
				'en_US'=> ucfirst(Zend_Locale::getTranslation('en', 'language', $locale)), 
				'de_DE'=> ucfirst(Zend_Locale::getTranslation('de', 'language', $locale)), 
				'da_DK'=> ucfirst(Zend_Locale::getTranslation('da', 'language', $locale)));
	}
	
	/**
	 * Get value of a option
	 * @param string $locale
	 * @return string
	 */
	public function getValue($locale) {
		$options = $this->getOptionsArray(true);
		$value = substr($locale, 0, 2);
		if (isset($options[$value])) {
			return $options[$value];
		} else {
			return null;
		}
	}
}